<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <title>消息列表</title>
    <link rel="stylesheet" type="text/css" th:href="@{/js/layui/css/layui.css}" media="all">
    <link rel="stylesheet" type="text/css" th:href="@{/css/fyn/style.css/}" media="all">
    <link rel="stylesheet" type="text/css" th:href="@{/css/fyn/my.css/}" media="all">

</head>
<body class="body">

<script type="text/html" id="topOperate">
    <div class="my-btn-box layui-form">
      <span class="fl">
    <!-- <button class="layui-btn layui-btn-sm" lay-event="toSave"><i class="layui-icon"></i>添加菜单</button> -->
        </span>
    </div>
</script>

<div class="my-btn-box layui-form">
    <span class="fr">
        <div class="layui-input-inline">
            <label class="layui-form-label">自动刷新</label>
             <input type="checkbox" name="close" lay-filter="close" lay-skin="switch" lay-text="开|关">

        </div>
         <!--<div class="layui-input-inline">-->
            <!--<input type="text" autocomplete="off" name="sendId" placeholder="发送人用户ID" class="layui-input height33">-->
        <!--</div>-->
        <div class="layui-input-inline">
            <input type="text" autocomplete="off" name="name" placeholder="发送人昵称" class="layui-input height33">
        </div>
        <!--        <div class="layui-input-inline">-->
        <!--            <input type="text" autocomplete="off" name="appId" placeholder="发送人用户号" class="layui-input height33">-->
        <!--        </div>-->
        <div class="layui-input-inline">
            <input type="text" autocomplete="off" name="content" placeholder="聊天内容" class="layui-input height33">
        </div>
        <div class="layui-input-inline">
            <input type="text" autocomplete="off" name="startTime" id="startTime" placeholder="开始时间"
                   class="layui-input height33">
        </div>
        <div class="layui-input-inline">
            <input type="text" autocomplete="off" name="endTime" id="endTime" placeholder="结束时间"
                   class="layui-input height33">
        </div>

        <button class="layui-btn layui-btn-sm" id="search"><i class="layui-icon">&#xe615;</i></button>
    </span>
</div>

<!-- 表格 -->
<div id="dateTable" lay-filter="event"></div>
<div class="height50"></div>
<script th:src="@{/js/layui/layui.js}"></script>
<script th:src="@{/js/fyn/index.js}"></script>
<script th:src="@{/js/fyn/my.js}"></script>
<script type="text/javascript" th:src="@{/js/vip/vip_comm.js}"></script>
<script type="text/javascript" th:src="@{/js/vip/vip_table.js}"></script>
<script type="text/javascript" th:inline="javascript">

    // layui方法
    layui.use(['table', 'form', 'laypage', 'layer', 'vip_table', 'laydate'], function () {

        // 操作对象
        var form = layui.form
            , table = layui.table
            , layer = layui.layer
            , vipTable = layui.vip_table
            , laydate = layui.laydate
            , $ = layui.jquery;
        //常规用法
        laydate.render({
            elem: '#startTime'
        });

        //常规用法
        laydate.render({
            elem: '#endTime'
        });

        var inter = null;

        form.on('switch(close)', function (data) {

            if (this.checked) {
                inter = setInterval(function () {
                    tableIns.reload(getJson());
                }, 10000);
            } else {
                clearInterval(inter);
            }

        });

        // 表格渲染
        var tableIns = table.render({
            elem: '#dateTable'                  //指定原始表格元素选择器（推荐id选择器）
            , height: "full"    //容器高度
            // , skin: 'line'
            , even: 'true'
            , cols: [[                  //标题栏
                {
                    field: 'menu.id', title: 'ID', minWidth: 100, sort: true, align: 'center', templet: function (d) {
                        return d.id;
                    }

                }
                , {
                    field: 'pName', title: '发送人', minWidth: 100, align: 'center', templet: function (d) {
                        return d.sendName;
                    }
                }

                , {
                    field: 'pName', title: '群组名称', minWidth: 100, align: 'center', templet: function (d) {
                        return d.receiveName;
                    }
                }
                , {
                    field: 'pName', title: '发送内容', minWidth: 100, align: 'center', templet: function (d) {
                        if (d.objectName.indexOf("ImgMsg") != -1) {
                            return "<div onclick=\"examine('"+d.content+"');\" id=\"viewImgId_"+d.LAY_INDEX+"\"><img src=\""+d.content+"\" width=\"30px;\" height=\"30px;\"></div>";
                        }
                        else if (d.objectName.indexOf("TxtMsg") != -1) {
                            return d.text;
                        }else {
                            return "";
                        }
                    }
                }
                , {
                    field: 'user.ctime',
                    align: 'center',
                    title: '发送时间',
                    sort: true,
                    minWidth: 150,
                    templet: function (d) {
                        return new Date(d.createTime).Format("yyyy-MM-dd hh:mm:ss");
                    }
                }
                , {title: '操作', align: 'center',minWidth: 250, toolbar: '#barOption'} //这里的toolbar值是模板元素的选择器
            ]]
            , id: 'dataCheck'
            , url: [[${basePath}]] + '/message/group/list'
            , method: 'get'
            , page: true
            , limits: [10, 30, 60, 90, 150, 300]
            , toolbar: '#topOperate'
            , limit: 10 //默认采用0
            , loading: true
            , where: getJson()
            , done: function (res, curr, count) {
                //如果是异步请求数据方式，res即为你接口返回的信息。
                //如果是直接赋值的方式，res即为：{data: [], count: 99} data为当前页数据、count为数据总长度
                $("td[data-field='content']").each(function () {
                    $(this).find(".layui-table-cell").removeClass('layui-table-cell');
                });


            }
        });


        //头工具栏事件
        table.on('toolbar(event)', function (obj) {
            var checkStatus = table.checkStatus(obj.config.id);
            var data = checkStatus.data;

            switch (obj.event) {
                case 'toSave':
                    layer.open({
                        type: 2,
                        title: '菜单增加',
                        shadeClose: true,
                        shade: 0.2,
                        maxmin: true, //开启最大化最小化按钮
                        area: ['650px', '550px'],
                        content: [[${basePath}]] + '/menu/save/index'
                    });
                    break;
            }
        });

        table.on('tool(event)', function (obj) {
            var data = obj.data;
            if (obj.event === 'edit') {

                layer.open({
                    type: 2,
                    title: '用户详情',
                    shadeClose: true,
                    shade: 0.2,
                    maxmin: true, //开启最大化最小化按钮
                    area: ['650px', '550px'],
                    content: [[${basePath}]] + '/member/detail?id=' + data.id
                });

            }

            //清除登录token
            if (obj.event === 'delete') {

                layer.confirm("确定删除此条聊天记录?", {
                    icon: 3,
                    title: '提示'
                }, function (index) {
                    $.ajax({
                        type: "post",
                        url: [[${basePath}]] + "/message/clean/single",
                        data: {id: data.id},
                        success: function (res) {
                            if (res.success) {
                                layer.msg("清除完成", {icon: 1}, 500);

                                layer.close(index);

                                tableIns.reload();
                            }
                        }
                    });


                });

            }

            if (obj.event === 'updateS') {

                layer.confirm("确定" + (data.status == 0 ? "冻结" : "开启") + "用户状态?", {
                    icon: 3,
                    title: '提示'
                }, function (index) {
                    $.ajax({
                        type: "post",
                        url: [[${basePath}]] + "/member/status/update",
                        data: {id: data.id, status: data.status == 0 ? 1 : 0},
                        success: function (res) {
                            if (res.success) {
                                layer.msg("操作完成", {icon: 1}, 500);

                                layer.close(index);

                                tableIns.reload();
                            }
                        }
                    });


                }, function (index) {


                });
            }

        });


        var status = 0;
        form.on('switch(status)', function (data) {
            if (!data.elem.checked) {
                status = 1;
            } else {
                status = 0;
            }

            $("#search").click();

        });


        function getJson() {
            return {
                where: {
                    sendName: $("input[name='name']").val()
                    , status: status
                    , startTime: $("input[name='startTime']").val()
                    , endTime: $("input[name='endTime']").val()
                    , sendId: $("input[name='sendId']").val()
                    , content: $("input[name='content']").val()

                }
            };
        }

        $("#search").click(function () {
            tableIns.reload({
                where: {
                    sendName: $("input[name='name']").val()
                    , status: status
                    , startTime: $("input[name='startTime']").val()
                    , endTime: $("input[name='endTime']").val()
                    , sendId: $("input[name='sendId']").val()
                    , content: $("input[name='content']").val()

                },
                page: {
                    curr: 1
                }
            });
        })


    });

    function examine(content) {
        layer.open({
            type: 1,
            title: '查看图片',
            shadeClose: true,
            shade: 0.2,
            maxmin: true, //开启最大化最小化按钮
            area: ['800px', '600px'],
            content: '<img src='+content+'>' //这里content是一个普通的String
        });
    }
</script>
<!-- 表格操作按钮集 -->
<script type="text/html" id="barOption">
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="delete"><i class="layui-icon layui-icon-delete"></i>删除</a>
</script>
</body>
</html>